package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.Travel;
import cn.wolfcode.luowowo.query.QueryObject;
import cn.wolfcode.luowowo.query.TravelQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import javafx.fxml.LoadException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo) {
        Page page = travelService.query(qo);
        model.addAttribute("page", page);
        return "travel/list";
    }

    //查看文章内容
    @RequestMapping("/getContentById")
    @ResponseBody
    public Object list(String id) {
        //返回游记的内容即可
        String content = travelService.get(id).getContent();

        return JsonResult.success(content);
    }

    //审核文章
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(String id, int state) throws LoadException {
        //审核通过之后，游记的字段需要改变的有：releaseTime  lastUpdateTime  state
        //明确需求：点赞收藏等统计的数量是否要请0
        travelService.changeState(id, state);
        return JsonResult.success();
    }

}
